package helper;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import databeans.Customer;
import databeans.Employee;

/*
 *  
 *  handle all code related to user session authentication
 */

public class UserSession {
    
    public static HttpSession setEmployeeIntoSession(HttpServletRequest request, Employee employee){
        HttpSession session = request.getSession(true); 
        session.setAttribute("employee", employee);
        return session;
    }
    
    public static HttpSession setCustomerIntoSession(HttpServletRequest request, Customer customer){
        HttpSession session = request.getSession(true); 
        session.setAttribute("customer", customer);
        return session;
    }
    
    //check for user is log in
    public static Customer getLoggedInCustomer (HttpServletRequest request){
        Customer customer = null;
        customer = (Customer) request.getSession(true).getAttribute("customer");
        return customer;
    }
    
    public static Employee getLoggedInEmployee(HttpServletRequest request ){
        Employee employee = null;
        employee = (Employee) request.getSession(true).getAttribute("employee");
        return employee;
    }
    
    public static HttpServletRequest removeCustomerFromSession (HttpServletRequest request){
        request.getSession(true).removeAttribute("customer");
        return request;
    }
    
    public static HttpServletRequest removeEmployeeFromSession (HttpServletRequest request){
        request.getSession(true).removeAttribute("employee");
        return request;
    }
    
    

}
